<?php
namespace common\components\exception;

use yii;
use yii\base\ErrorHandler as BaseErrorHandler;

class ErrorHandler extends BaseErrorHandler
{
    public  $errorAction;

    public $errorView = '@app/views/errorHandler/error.php';
    public function renderException($exception)
    {
        if(Yii::$app->request->getIsAjax()){
            exit( json_encode( array('code' =>$exception->getCode(),'msg'  =>$exception->getMessage()) ));
        }else{
            if (YII_DEBUG) {
                echo  $exception->getMessage();
            }else{
                echo  Yii::$app->getView()->renderFile($this->errorView,['exception' => $exception,],$this);
            }
        }
    }

    public function errorAction($exception){
        if(Yii::$app->request->getIsAjax()){
            exit( json_encode( array('code' =>$exception->getCode(),'msg'  =>$exception->getMessage()) ));
        }else{
            if (YII_DEBUG) {
                echo  $exception->getMessage();
            }else{
                echo  Yii::$app->getView()->renderFile($this->errorView,['exception' => $exception,],$this);
            }
        }
    }
}